import { order } from 'mockjs/src/mock/random/helper';

export function setOption(self) {
  return {
    lazy: true,
    rowKey: 'id',
    rowParentKey: 'parentId',
    height: 'calc(100vh - 440px)',
    calcHeight: 30,
    tip: false,
    searchShow: true,
    searchMenuSpan: 6,
    border: true,
    index: false,
    viewBtn: false,
    editBtn: true,
    delBtn: false,
    addBtn: false,
    viewBtnText: '详情',
    viewTitle: '详情',
    indexLabel: '序号',
    columnBtn: false,
    selection: true,
    menuWidth: 280,
    column: [
      {
        label: '名称',
        prop: 'name',
        labelWidth: 150,
        search: true,
        rules: [
          {
            required: true,
            message: '请输入名称',
            trigger: 'blur'
          }
        ],
        order: 1
      },
      {
        label: '编码',
        prop: 'code',
        labelWidth: 150,
        search: true,
        editDisabled: true,
        order: 2,
        rules: [
          {
            required: true,
            message: '请输入编码',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '等级',
        prop: 'levelName',
        addDisplay: false,
        editDisplay: false
      },
      {
        label: '物料存储等级',
        labelWidth: 150,
        prop: 'materialStorageLevel',
        type: 'select',
        hide: true,
        order: 7,
        props: {
          label: 'label',
          value: 'value'
        },
        dicData: [
          { label: 'L1', value: 1 },
          { label: 'L2', value: 2 },
          { label: 'L3', value: 3 },
          { label: 'L4', value: 4 },
          { label: 'L5', value: 5 },
          { label: 'L6', value: 6 },
          { label: 'L7', value: 7 },
          { label: 'L8', value: 8 },
          { label: 'L9', value: 9 },
          { label: 'L10', value: 10 }
        ],
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE') {
            return {
              materialStorageLevel: {
                addDisplay: true,
                editDisplay: true
              }
            };
          } else {
            return {
              materialStorageLevel: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        }
      },
      {
        label: '地址',
        prop: 'locationName',
        labelWidth: 150,
        type: 'search',
        order: 9,
        disabled: true,
        hide: true,
        appendClick: () => {
          self.openLocationCommonModal();
        },
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE') {
            return {
              locationName: {
                addDisplay: true,
                editDisplay: true
              }
            };
          } else {
            return {
              locationName: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        }
      },
      {
        label: '仓库类型',
        prop: 'inventoryType',
        search: true,
        type: 'select',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=inventory_type',
        labelWidth: 150,
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE') {
            return {
              inventoryType: {
                addDisplay: true,
                editDisplay: true,
                editDisabled: true
              }
            };
          } else {
            return {
              inventoryType: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        },
        order: 3,
        rules: [
          {
            required: true,
            message: '请选择仓库类型',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '子属性',
        prop: 'inventorySubType',
        labelWidth: 150,
        type: 'select',
        order: 4,
        value: '',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        formatter: (val) => {
          return val.inventorySubTypeName;
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=warehouse_sub_type',
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE') {
            return {
              inventorySubType: {
                addDisplay: true,
                editDisplay: true
              }
            };
          } else {
            return {
              inventorySubType: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        },
        rules: [
          {
            required: true,
            message: '请选择子属性',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '所属车间',
        prop: 'workshopId',
        labelWidth: 150,
        type: 'select',
        order: 4,
        value: '',
        props: {
          label: 'name',
          value: 'id'
        },
        filterable: true,
        dicFormatter: (res) => {
          self.workshopList = res.data.records || [];
          return res.data.records;
        },
        dicUrl: '/api/mes-admin/workshop/page?current=1&size=10000',
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE' && form.inventoryType === 'LINE_SIDE') {
            return {
              workshopId: {
                addDisplay: true,
                editDisplay: true
              }
            };
          } else {
            return {
              workshopId: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        },
        change: ({ column, value }) => {
          if (value) {
            let findNode = self._find(self.workshopList, { id: value });
            self.form.workshopName = findNode.name || '';
            self.form.workshopCode = findNode.code || '';
          }
        },
        rules: [
          {
            required: true,
            message: '请选择所属车间',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '储位类型',
        labelWidth: 150,
        prop: 'areaTypeName',
        addDisplay: false,
        editDisplay: false,
        formatter: (val) => {
          if (val.areaTypeName === '仓库') {
            return '';
          } else {
            return val.areaTypeName;
          }
        }
      },
      {
        label: '默认储位',
        labelWidth: 150,
        prop: 'isDefault',
        type: 'switch',
        value: false,
        order: 14,
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              isDefault: {
                addDisplay: true,
                editDisplay: true,
                label: '默认储位',
                labelTip: '启动后，紧急入库或入库无需上架是默认入库区',
                order: 14
              }
            };
          } else {
            return {
              isDefault: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        },
        dicData: [
          {
            label: '否',
            value: false
          },
          {
            label: '是',
            value: true
          }
        ]
      },
      {
        label: '颜色标识',
        labelWidth: 150,
        prop: 'color',
        type: 'color',
        order: 6,
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              color: {
                addDisplay: true,
                editDisplay: true
              }
            };
          } else {
            return {
              color: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        }
      },
      // {
      //   label: '物料管控先进先出',
      //   width: 150,
      //   prop: 'fifoRequired',
      //   type: 'switch',
      //   value: false,
      //   order: 6,
      //   labelWidth: 150,
      //   dicData: [
      //     {
      //       label: '否',
      //       value: false
      //     },
      //     {
      //       label: '是',
      //       value: true
      //     }
      //   ],
      //   // formatter: (val) => {
      //   //   return val.fifoRequiredName;
      //   // },
      //   control: (val, form) => {
      //     if (self.addType === 'WAREHOUSE') {
      //       return {
      //         fifoRequired: {
      //           addDisplay: true,
      //           editDisplay: true
      //         }
      //       };
      //     } else {
      //       return {
      //         fifoRequired: {
      //           addDisplay: false,
      //           editDisplay: false
      //         }
      //       };
      //     }
      //   }
      // },
      {
        label: '启用',
        labelWidth: 150,
        prop: 'status',
        type: 'switch',
        value: 1,
        order: 12,
        // formatter: (val) => {
        //   return val.areaStatusName;
        // },
        dicData: [
          {
            label: '否',
            value: 0
          },
          {
            label: '是',
            value: 1
          }
        ]
      },
      {
        label: '负责人',
        prop: 'principalName',
        labelWidth: 150,
        order: 10,
        type: 'search',
        disabled: true,
        appendClick: () => {
          self.openUserCommonModal();
        },
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              principalName: {
                addDisplay: false,
                editDisplay: false
              }
            };
          } else {
            return {
              principalName: {
                addDisplay: true,
                editDisplay: true
              }
            };
          }
        }
      },
      {
        label: '联系方式',
        prop: 'contacts',
        order: 11,
        labelWidth: 150,
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              contacts: {
                addDisplay: false,
                editDisplay: false
              }
            };
          } else {
            return {
              contacts: {
                addDisplay: true,
                editDisplay: true
              }
            };
          }
        }
      },
      {
        label: '备注',
        order: 13,
        labelWidth: 150,
        prop: 'remark'
      },
      {
        label: '货架类型',
        prop: 'materialAnalysisLevel',
        type: 'select',
        labelWidth: 150,
        hide: true,
        value: 'LOT_LEVEL',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=MATERIALANALYSISLEVEL',
        rules: [
          {
            required: true,
            message: '请选择货架类型',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              materialAnalysisLevel: {
                addDisplay: false,
                editDisplay: false
              }
            };
          } else {
            return {
              materialAnalysisLevel: {
                addDisplay: true,
                editDisplay: true
              }
            };
          }
        }
      },
      {
        label: '默认备料区',
        prop: 'subAreaType',
        type: 'switch',
        labelWidth: 150,
        hide: true,
        labelTip: '启动后，备料拣货后物料会默认在备料区',
        dicData: [
          {
            label: '否',
            value: ''
          },
          {
            label: '是',
            value: 'MTPA'
          }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              subAreaType: {
                addDisplay: true,
                editDisplay: true
              }
            };
          } else {
            return {
              subAreaType: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        }
      }
    ]
  };
}

export function setDetailOption(type) {
  return {
    calcHeight: 30,
    tip: false,
    searchShow: true,
    searchMenuSpan: 6,
    border: true,
    index: true,
    viewBtn: false,
    editBtn: false,
    delBtn: false,
    addBtn: false,
    viewBtnText: '详情',
    viewTitle: '详情',
    indexLabel: '序号',
    columnBtn: false,
    menuWidth: 280,
    column: [
      {
        label: '名称',
        prop: 'name',
        labelWidth: 150,
        order: 1
      },
      {
        label: '编码',
        prop: 'code',
        labelWidth: 150,
        order: 2
      },
      {
        label: '地址',
        prop: 'locationName',
        labelWidth: 150,
        type: 'search',
        order: 9,
        disabled: true,
        control: (val, form) => {
          if (type === 'WAREHOUSE') {
            return {
              locationName: {
                display: true
              }
            };
          } else {
            return {
              locationName: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '仓库类型',
        prop: 'inventoryType',
        search: true,
        type: 'select',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=inventory_type',
        labelWidth: 150,
        control: (val, form) => {
          if (type === 'WAREHOUSE') {
            return {
              inventoryType: {
                display: true
              }
            };
          } else {
            return {
              inventoryType: {
                display: false
              }
            };
          }
        },
        order: 3
      },
      {
        label: '子属性',
        prop: 'inventorySubTypeName',
        labelWidth: 150,
        type: 'select',
        order: 4,
        value: 'GENERAL',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=warehouse_sub_type',
        control: (val, form) => {
          if (type === 'WAREHOUSE') {
            return {
              inventorySubTypeName: {
                display: true
              }
            };
          } else {
            return {
              inventorySubTypeName: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '所属车间',
        prop: 'workshopName',
        labelWidth: 150,
        order: 4.5,
        control: (val, form) => {
          if (form.inventoryType === 'LINE_SIDE') {
            return {
              workshopName: {
                addDisplay: true,
                editDisplay: true
              }
            };
          } else {
            return {
              workshopName: {
                addDisplay: false,
                editDisplay: false
              }
            };
          }
        }
      },
      {
        label: '等级',
        prop: 'levelName',
        labelWidth: 150,
        order: 5
      },
      {
        label: '储位类型',
        labelWidth: 150,
        prop: 'inventoryTypeName',
        order: 4,
        control: (val, form) => {
          if (type === 'WAREHOUSE') {
            return {
              inventoryTypeName: {
                display: false
              }
            };
          } else {
            return {
              inventoryTypeName: {
                display: true
              }
            };
          }
        }
      },
      {
        label: '默认储位',
        labelWidth: 150,
        order: 14,
        prop: 'isDefault',
        type: 'switch',
        value: false,
        control: (val, form) => {
          if (type === 'STORAGE') {
            return {
              isDefault: {
                display: true,
                label: '默认储位',
                labelTip: '启动后，紧急入库或入库无需上架是默认入库区',
                order: 14
              }
            };
          } else {
            return {
              isDefault: {
                display: false
              }
            };
          }
        },
        dicData: [
          {
            label: '否',
            value: false
          },
          {
            label: '是',
            value: true
          }
        ]
      },
      {
        label: '颜色标识',
        labelWidth: 150,
        prop: 'color',
        order: 6,
        control: (val, form) => {
          if (type === 'STORAGE') {
            return {
              color: {
                display: true
              }
            };
          } else {
            return {
              color: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '启用',
        labelWidth: 150,
        prop: 'status',
        type: 'switch',
        value: true,
        order: 12,
        dicData: [
          {
            label: '否',
            value: 0
          },
          {
            label: '是',
            value: 1
          }
        ]
      },
      {
        label: '负责人',
        prop: 'principalName',
        labelWidth: 150,
        order: 10,
        type: 'search',
        disabled: true,
        control: (val, form) => {
          if (type === 'STORAGE') {
            return {
              principalName: {
                display: false
              }
            };
          } else {
            return {
              principalName: {
                display: true
              }
            };
          }
        }
      },
      {
        label: '联系方式',
        prop: 'contacts',
        order: 11,
        labelWidth: 150,
        control: (val, form) => {
          if (type === 'STORAGE') {
            return {
              contacts: {
                display: false
              }
            };
          } else {
            return {
              contacts: {
                display: true
              }
            };
          }
        }
      },
      {
        label: '备注',
        order: 13,
        labelWidth: 150,
        prop: 'remark'
      },
      {
        label: '货架类型',
        prop: 'materialAnalysisLevel',
        type: 'select',
        labelWidth: 150,
        hide: true,
        value: 'LOT_LEVEL',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=MATERIALANALYSISLEVEL',
        rules: [
          {
            required: true,
            message: '请选择货架类型',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (type === 'STORAGE') {
            return {
              materialAnalysisLevel: {
                display: false
              }
            };
          } else {
            return {
              materialAnalysisLevel: {
                display: true
              }
            };
          }
        }
      },
      {
        label: '默认备料区',
        prop: 'subAreaType',
        type: 'switch',
        labelWidth: 150,
        hide: true,
        labelTip: '启动后，备料拣货后物料会默认在备料区',
        dicData: [
          {
            label: '否',
            value: ''
          },
          {
            label: '是',
            value: 'MTPA'
          }
        ],
        control: (val, form) => {
          if (type === 'STORAGE') {
            return {
              subAreaType: {
                display: true
              }
            };
          } else {
            return {
              subAreaType: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架面',
        prop: 'shelfSide',
        type: 'select',
        labelWidth: 150,
        hide: true,
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=SHELF_SIDE',
        rules: [
          {
            required: true,
            message: '货架面',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          console.log(type, form.materialAnalysisLevel);
          if (type === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfSide: {
                display: true
              }
            };
          } else if (type === 'STORAGE') {
            if (form.materialAnalysisLevel === 'PACK_LEVEL') {
              return {
                shelfSide: {
                  display: true
                }
              };
            } else {
              return {
                shelfSide: {
                  display: true,
                  rules: []
                }
              };
            }
          } else {
            return {
              shelfSide: {
                display: false
              }
            };
          }
        }
      }
    ]
  };
}

export function setShelfDetailOption(type) {
  return {
    calcHeight: 30,
    tip: false,
    searchShow: true,
    searchMenuSpan: 6,
    border: true,
    index: true,
    viewBtn: false,
    editBtn: false,
    delBtn: false,
    addBtn: false,
    viewBtnText: '详情',
    viewTitle: '详情',
    indexLabel: '序号',
    columnBtn: false,
    menuWidth: 280,
    column: [
      {
        label: '货架型号',
        labelWidth: 150,
        prop: 'shelfModel',
        control: (val, form) => {
          if (type === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfModel: {
                display: true
              }
            };
          } else {
            return {
              shelfModel: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '是否感应货架',
        prop: 'shelfIsInduction',
        labelWidth: 150,
        type: 'select',
        dicData: [
          { label: '是', value: true },
          { label: '否', value: false }
        ],
        control: (val, form) => {
          if (type === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfIsInduction: {
                display: true
              }
            };
          } else {
            return {
              shelfIsInduction: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架端口',
        labelWidth: 150,
        prop: 'shelfPort',
        rules: [
          {
            required: true,
            message: '请输入货架端口',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (type === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfPort: {
                display: true
              }
            };
          } else {
            return {
              shelfPort: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架服务端口',
        labelWidth: 150,
        prop: 'shelfServerPort',
        rules: [
          {
            required: true,
            message: '请输入货架服务端口',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (type === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfServerPort: {
                display: true
              }
            };
          } else {
            return {
              shelfServerPort: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '通讯类型',
        labelWidth: 150,
        prop: 'shelfCommunicationType',
        control: (val, form) => {
          if (type === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfCommunicationType: {
                display: true
              }
            };
          } else {
            return {
              shelfCommunicationType: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架IP',
        prop: 'shelfIp',
        labelWidth: 150,
        rules: [
          {
            required: true,
            message: '请输入货架IP',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (type === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfIp: {
                display: true
              }
            };
          } else {
            return {
              shelfIp: {
                display: false
              }
            };
          }
        }
      }
    ]
  };
}

export function setEditOption(self) {
  return {
    submitBtn: false,
    emptyBtn: false,
    column: [
      {
        label: '',
        prop: 'baseInfo',
        order: 0,
        span: 24,
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA') {
            return {
              baseInfo: {
                display: true
              }
            };
          } else {
            return {
              baseInfo: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '名称',
        prop: 'name',
        labelWidth: 150,
        search: true,
        rules: [
          {
            required: true,
            message: '请输入名称',
            trigger: 'blur'
          }
        ],
        order: 1
      },
      {
        label: '编码',
        prop: 'code',
        labelWidth: 150,
        search: true,
        editDisabled: true,
        order: 2,
        rules: [
          {
            required: true,
            message: '请输入编码',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '等级',
        labelWidth: 150,
        prop: 'levelName',
        addDisplay: false,
        editDisplay: false
      },
      {
        label: '物料存储等级',
        labelWidth: 150,
        prop: 'materialStorageLevel',
        type: 'select',
        hide: true,
        order: 7,
        props: {
          label: 'label',
          value: 'value'
        },
        dicData: [
          { label: 'L1', value: 1 },
          { label: 'L2', value: 2 },
          { label: 'L3', value: 3 },
          { label: 'L4', value: 4 },
          { label: 'L5', value: 5 },
          { label: 'L6', value: 6 },
          { label: 'L7', value: 7 },
          { label: 'L8', value: 8 },
          { label: 'L9', value: 9 },
          { label: 'L10', value: 10 }
        ],
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE') {
            return {
              materialStorageLevel: {
                display: true
              }
            };
          } else {
            return {
              materialStorageLevel: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '地址',
        prop: 'locationName',
        labelWidth: 150,
        type: 'search',
        order: 9,
        disabled: true,
        hide: true,
        appendClick: () => {
          self.openLocationCommonModal();
        },
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE') {
            return {
              locationName: {
                display: true
              }
            };
          } else {
            return {
              locationName: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '仓库类型',
        prop: 'inventoryType',
        search: true,
        type: 'select',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=inventory_type',
        labelWidth: 150,
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE') {
            return {
              inventoryType: {
                display: true
              }
            };
          } else {
            return {
              inventoryType: {
                display: false
              }
            };
          }
        },
        order: 3,
        rules: [
          {
            required: true,
            message: '请选择仓库类型',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '子属性',
        prop: 'inventorySubType',
        labelWidth: 150,
        type: 'select',
        order: 4,
        value: '',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        formatter: (val) => {
          return val.inventorySubTypeName;
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=warehouse_sub_type',
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE') {
            return {
              inventorySubType: {
                display: true
              }
            };
          } else {
            return {
              inventorySubType: {
                display: false
              }
            };
          }
        },
        rules: [
          {
            required: true,
            message: '请选择子属性',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '所属车间',
        prop: 'workshopId',
        labelWidth: 150,
        type: 'select',
        order: 4,
        value: '',
        props: {
          label: 'name',
          value: 'id'
        },
        filterable: true,
        dicFormatter: (res) => {
          self.workshopList = res.data.records || [];
          return res.data.records;
        },
        dicUrl: '/api/mes-admin/workshop/page?current=1&size=10000',
        control: (val, form) => {
          if (self.addType === 'WAREHOUSE' && form.inventoryType === 'LINE_SIDE') {
            return {
              workshopId: {
                display: true
              }
            };
          } else {
            return {
              workshopId: {
                display: false
              }
            };
          }
        },
        change: ({ column, value }) => {
          if (value) {
            let findNode = self._find(self.workshopList, { id: value });
            self.form.workshopName = findNode.name || '';
            self.form.workshopCode = findNode.code || '';
          }
        },
        rules: [
          {
            required: true,
            message: '请选择所属车间',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '默认储位',
        labelWidth: 150,
        prop: 'isDefault',
        type: 'switch',
        value: false,
        order: 14,
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              isDefault: {
                display: true,
                label: '默认储位',
                labelTip: '启动后，紧急入库或入库无需上架是默认入库区',
                order: 14
              }
            };
          } else {
            return {
              isDefault: {
                display: false
              }
            };
          }
        },
        dicData: [
          {
            label: '否',
            value: false
          },
          {
            label: '是',
            value: true
          }
        ]
      },
      {
        label: '颜色标识',
        labelWidth: 150,
        prop: 'color',
        type: 'color',
        order: 6,
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              color: {
                display: true
              }
            };
          } else {
            return {
              color: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '启用',
        labelWidth: 150,
        prop: 'status',
        type: 'switch',
        value: 1,
        order: 12,
        dicData: [
          {
            label: '否',
            value: 0
          },
          {
            label: '是',
            value: 1
          }
        ]
      },
      {
        label: '负责人',
        prop: 'principalName',
        labelWidth: 150,
        order: 10,
        type: 'search',
        disabled: true,
        appendClick: () => {
          self.openUserCommonModal();
        },
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              principalName: {
                display: false
              }
            };
          } else {
            return {
              principalName: {
                display: true
              }
            };
          }
        }
      },
      {
        label: '联系方式',
        prop: 'contacts',
        order: 11,
        labelWidth: 150,
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              contacts: {
                display: false
              }
            };
          } else {
            return {
              contacts: {
                display: true
              }
            };
          }
        }
      },
      {
        label: '备注',
        order: 13,
        labelWidth: 150,
        prop: 'remark'
      },
      {
        label: '货架类型',
        prop: 'materialAnalysisLevel',
        type: 'select',
        labelWidth: 150,
        hide: true,
        value: 'LOT_LEVEL',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=MATERIALANALYSISLEVEL',
        rules: [
          {
            required: true,
            message: '请选择货架类型',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              materialAnalysisLevel: {
                display: false
              }
            };
          } else {
            return {
              materialAnalysisLevel: {
                display: true
              }
            };
          }
        }
      },
      {
        label: '默认备料区',
        prop: 'subAreaType',
        type: 'switch',
        labelWidth: 150,
        hide: true,
        labelTip: '启动后，备料拣货后物料会默认在备料区',
        dicData: [
          {
            label: '否',
            value: ''
          },
          {
            label: '是',
            value: 'MTPA'
          }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE') {
            return {
              subAreaType: {
                display: true
              }
            };
          } else {
            return {
              subAreaType: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架面',
        prop: 'shelfSide',
        type: 'select',
        labelWidth: 150,
        hide: true,
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        dicUrl: '/api/blade-system/dict/dictionary?code=SHELF_SIDE',
        rules: [
          {
            required: true,
            message: '货架面',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfSide: {
                display: true
              }
            };
          } else if (self.addType === 'STORAGE') {
            if (self.selectionList.length && self.selectionList[0].materialAnalysisLevel === 'PACK_LEVEL') {
              return {
                shelfSide: {
                  display: true
                }
              };
            } else {
              return {
                shelfSide: {
                  display: true,
                  rules: []
                }
              };
            }
          } else {
            return {
              shelfSide: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '',
        prop: 'shelf',
        span: 24,
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelf: {
                display: true
              }
            };
          } else {
            return {
              shelf: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架型号',
        labelWidth: 150,
        prop: 'shelfModel',
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfModel: {
                display: true
              }
            };
          } else {
            return {
              shelfModel: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '是否感应货架',
        prop: 'shelfIsInduction',
        labelWidth: 150,
        type: 'select',
        dicData: [
          { label: '是', value: true },
          { label: '否', value: false }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfIsInduction: {
                display: true
              }
            };
          } else {
            return {
              shelfIsInduction: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架端口',
        labelWidth: 150,
        prop: 'shelfPort',
        rules: [
          {
            required: true,
            message: '请输入货架端口',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfPort: {
                display: true
              }
            };
          } else {
            return {
              shelfPort: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架服务端口',
        labelWidth: 150,
        prop: 'shelfServerPort',
        rules: [
          {
            required: true,
            message: '请输入货架服务端口',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfServerPort: {
                display: true
              }
            };
          } else {
            return {
              shelfServerPort: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '通讯类型',
        labelWidth: 150,
        prop: 'shelfCommunicationType',
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfCommunicationType: {
                display: true
              }
            };
          } else {
            return {
              shelfCommunicationType: {
                display: false
              }
            };
          }
        }
      },
      {
        label: '货架IP',
        prop: 'shelfIp',
        labelWidth: 150,
        rules: [
          {
            required: true,
            message: '请输入货架IP',
            trigger: 'blur'
          }
        ],
        control: (val, form) => {
          if (self.addType === 'STORAGE_AREA' && form.materialAnalysisLevel === 'PACK_LEVEL') {
            return {
              shelfIp: {
                display: true
              }
            };
          } else {
            return {
              shelfIp: {
                display: false
              }
            };
          }
        }
      }
    ]
  };
}
